﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.BizTalk.BaseFunctoids;
using System.Reflection;

namespace Biztalk.Functoids.Guid
{
    [Serializable]
    public class NewGuidSQLSERVER : BaseFunctoid
    {
        public NewGuidSQLSERVER()
            : base()
        {
            //ID for this functoid
            this.ID = 10100;

            // resource assembly must be ProjectName.ResourceName if building with VS.Net
            SetupResourceAssembly("Biztalk.Functoids.Guid.StringResources", Assembly.GetExecutingAssembly());

            //Setup the Name, ToolTip, Help Description, and the Bitmap for this functoid
            SetName("IDS_GUIDTO_SQL");
            SetTooltip("IDS_NEWGUIDFUNCTOIDSQL_TOOLTIP");
            SetDescription("IDS_NEWGUIDFUNCTOIDSQL_DESCRIPTION");
            SetBitmap("IDS_ADVCOMPAREFUNCTOI_BITMAP");

            //category for this functoid. This functoid goes under the String Functoid Tab in the
            this.Category = FunctoidCategory.String;

            //// Set the limits for the number of input parameters. This example: 1 parameter
            //this.SetMinParams(3);
            //this.SetMaxParams(3);

            //// Add one line of code as set out below for each input param. For multiple input params, each line would be identical.
            //AddInputConnectionType(ConnectionType.AllExceptRecord); //first input
            //AddInputConnectionType(ConnectionType.AllExceptRecord); //Second input
            //AddInputConnectionType(ConnectionType.AllExceptRecord); //Third input

            // The functoid output can go to any node type.
            this.OutputConnectionType = ConnectionType.AllExceptRecord;

            // Set the function name that is to be called when invoking this functoid.
            // To test the map in Visual Studio, this functoid does not need to be in the GAC.
            // If using this functoid in a deployed BizTalk app. then it must be in the GAC
            SetExternalFunctionName(GetType().Assembly.FullName, GetType().FullName, "NewGuidSQLSERVERS");

            SetScriptBuffer(ScriptType.CSharp, this.GetCSharpBuffer());
            HasSideEffects = false;

        }

        /// <summary>
        /// Retourne new guid.
        /// </summary>
          public string NewGuidSQLSERVERS()
        {

            return System.Guid.NewGuid().ToString();
        }
        private string GetCSharpBuffer()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("public string NewGuidSQLSERVERS()\n");
            builder.Append("{\n");
            builder.Append("\treturn System.Guid.NewGuid().ToString();\n");
            builder.Append("}\n");
            return builder.ToString();
        }
    }
}


